package com.zzdx.deployment.web.controller.common;

import com.zzdx.deployment.system.domain.ProductVersion;
import com.zzdx.deployment.system.domain.Project;
import com.zzdx.deployment.system.domain.ProjectVersion;

import java.util.List;

/**
 * @Description 公共函数
 * @Author Mason
 * @Date 2018/12/28
 **/
public class CommonFunction {

    /**
     * 根据project对象数组，获取其id并使用","连接为字符串
     * @param projectObjects
     * @return
     */
    public static String  convertToProjectIdStr(List<Project> projectObjects) {
        StringBuilder projectIds = new StringBuilder();
        for (int i =0; i< projectObjects.size();i++){
            Project project = projectObjects.get(i);
            if(i == 0){
                projectIds.append(project.getId());
            }else{
                projectIds.append(","+project.getId());
            }
        }

        return projectIds.toString();
    }

    /**
     * 根据projectVersion对象数组，获取其id并使用","连接为字符串
     * @param projectVersionObjects
     * @return
     */
    public static String  convertToProjectVersionIdStr(List<ProjectVersion> projectVersionObjects) {
        StringBuilder projectIds = new StringBuilder();
        for (int i =0; i< projectVersionObjects.size();i++){
            ProjectVersion projectVersion = projectVersionObjects.get(i);
            if(i == 0){
                projectIds.append(projectVersion.getId());
            }else{
                projectIds.append(","+projectVersion.getId());
            }
        }

        return projectIds.toString();
    }

    /**
     * 根据productVersion对象数组，获取其id并使用","连接为字符串
     * @param productVersionObjects
     * @return
     */
    public static String  convertToProductVersionIdStr(List<ProductVersion> productVersionObjects) {
        StringBuilder projectIds = new StringBuilder();
        for (int i =0; i< productVersionObjects.size();i++){
            ProductVersion projectVersion = productVersionObjects.get(i);
            if(i == 0){
                projectIds.append(projectVersion.getId());
            }else{
                projectIds.append(","+projectVersion.getId());
            }
        }

        return projectIds.toString();
    }
}
